<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/common_setting_unit.php"); ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--網站語言-->
    <meta http-equiv="Content-Language" content="zh-cn">
    <!--網站編碼-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php include '../coresection/title.php'; ?></title>
    <link rel="Shortcut Icon" href="../coresection/logoicon.ico">


</head>

<body style="display: none;">

<?
//设置需要搜索的表格的前缀后缀
global $table_Prefix;
$table_Suffix = "threed";
$table = $table_Prefix . $table_Suffix;
//设置需要搜索的表格的前缀后缀

?>


<?php
$nid = $_REQUEST['nid'];
$is_3d = false;
$is_images= false;
if(is_uploaded_file($_FILES['3d']['tmp_name'])){
	
	$threed_upfile = $_FILES["3d"];
	
	$threed_tmp_name = $threed_upfile["tmp_name"]; //上传文件的临时存放路径
	
	$threed_name = $nid.".3ds";
	
	move_uploaded_file($threed_tmp_name, '../../uploadfiles/' . $theme_folder . '/' . $threed_name);

	$sql = "INSERT INTO $table (image,detail_longnid,img_order) value ('$threed_name','$nid','0')";
    sql_log($sql);
$query = mysql_query($sql) or die ('保存3D图失败！');
	
	$is_3d = true;
}

if(is_uploaded_file($_FILES['image1']['tmp_name']) &&
    is_uploaded_file($_FILES['image2']['tmp_name']) &&
    is_uploaded_file($_FILES['image3']['tmp_name']) &&
    is_uploaded_file($_FILES['image4']['tmp_name']) &&
    is_uploaded_file($_FILES['image5']['tmp_name']) &&
    is_uploaded_file($_FILES['image6']['tmp_name']) &&
    is_uploaded_file($_FILES['image7']['tmp_name']) &&
    is_uploaded_file($_FILES['image8']['tmp_name']) &&
    is_uploaded_file($_FILES['image9']['tmp_name']) &&
    is_uploaded_file($_FILES['image10']['tmp_name']) &&
    is_uploaded_file($_FILES['image11']['tmp_name']) &&
    is_uploaded_file($_FILES['image12']['tmp_name']) &&
    is_uploaded_file($_FILES['image13']['tmp_name']) &&
    is_uploaded_file($_FILES['image14']['tmp_name']) &&
    is_uploaded_file($_FILES['image15']['tmp_name']) &&
    is_uploaded_file($_FILES['image16']['tmp_name']))
{
	
	$is_images= true;
	
    for($i=0;$i<16;$i++){

            $upfile = $_FILES["image".$i.""];

            $longnid = "D".$nid;
            $longname = $longnid."_".$i;

//            $name = $upfile["name"];
//            $cutto = strrpos($name, ".");
//            $name = substr_replace($name, $longname, 0, $cutto);

            $name = $longname.".png";

            $type = $upfile["type"]; //上传文件的类型
            $size = $upfile["size"]; //上传文件的大小
            $tmp_name = $upfile["tmp_name"]; //上传文件的临时存放路径
            /*
            这是一种非常简单文件上传方式。基于安全方面的考虑，您应当增加有关什么用户有权上传文件的限制。
            上传限制
            在这个脚本中，我们增加了对文件上传的限制。用户只能上传 .gif 或 .jpeg 文件
            */
            switch ($type) {
                case 'image/pjpeg':
                    $okType = true;
                    break;
                case 'image/jpeg':
                    $okType = true;
                    break;
                case 'image/gif':
                    $okType = true;
                    break;
                case 'image/png':
                    $okType = true;
                    break;
            }


            if ($okType) {
                /**
                 * 0:文件上传成功<br/>
                 * 1：超过了文件大小，在php.ini文件中设置<br/>
                 * 2：超过了文件的大小MAX_FILE_SIZE选项指定的值<br/>
                 * 3：文件只有部分被上传<br/>
                 * 4：没有文件被上传<br/>
                 * 5：上传文件大小为0
                 */
                $error = $upfile["error"]; //上传后系统返回的值
                echo "================<br/>";
                echo "上传文件名称是：" . $name . "<br/>";
                echo "上传文件类型是：" . $type . "<br/>";
                echo "上传文件大小是：" . $size . "<br/>";
                echo "上传后系统返回的值是：" . $error . "<br/>";
                echo "上传文件的临时存放路径是：" . $tmp_name . "<br/>";

                echo "开始移动上传文件<br/>";
                //把上传的临时文件移动到up目录下面
                move_uploaded_file($tmp_name, '../../uploadfiles/' . $theme_folder . '/' . $name);
                $image = $name;
                echo "================<br/>";
                echo "上传信息：<br/>";
                if ($error == 0) {
                    echo "文件上传成功啦！";
                    echo "<br>图片预览:<br>";
                    echo "<img src=" . $destination . ">";
                    //echo " alt="图片预览:r文件名:".$destination."r上传时间:">";
                } elseif ($error == 1) {
                    echo "超过了文件大小，在php.ini文件中设置";
                } elseif ($error == 2) {
                    echo "超过了文件的大小MAX_FILE_SIZE选项指定的值";
                } elseif ($error == 3) {
                    echo "文件只有部分被上传";
                } elseif ($error == 4) {
                    echo "没有文件被上传";
                } else {
                    echo "上传文件大小为0";
                }
            } else {
                echo "请上传jpg,gif,png等格式的图片！";
            }


        $sql = "INSERT INTO $table (image,detail_longnid,img_order) value ('$image','$nid','$i')";
        sql_log($sql);
$query = mysql_query($sql) or die ('保存3D图失败！');
        mysql_close($con);
    }

 

}

if($is_images == true && $is_3d == true){
?>
	 <script type="text/javascript">
        alert("3D展示图片跟3D文件已保存，请点击返回！");
        document.location.href = "../detail/detail-list.php?sys_part=product";
    </script>
<?php
}
elseif($is_3d == true){
?>
	<script type="text/javascript">
        alert("3D文件已保存，请点击返回！");
        document.location.href = "../detail/detail-list.php?sys_part=product";
    </script>
<?php 
}
elseif($is_images == true){
?>
	<script type="text/javascript">
        alert("3D展示图片已保存，请点击返回！");
        document.location.href = "../detail/detail-list.php?sys_part=product";
    </script>
<?php 
}else{
?>
<script type="text/javascript">
    alert("为确保3D展示系统正常运行，请检查16张图片是否已上传！");
    document.location.href = "detail-add.php?nid=<?echo $nid?>";
</script>

<?

}


?>
</body>